var app = getApp()
Page({
  data: {
    line: 1,
    line1Data: [],
    line2Data: [],
    idx: []
  },
  clickMap: function() {
    // 点击查看照片
wx.previewImage({
  urls: ['http://inews.gtimg.com/newsapp_bt/0/989775047/641','http://www.jlonline.com/d/file/guoneiredian/20170104/6d97ed2e2763936a58bc070ec5592eb7.jpg'] // 需要预览的图片http链接列表
})
  },
  switchLine1: function () {
    this.setData({
      line: 1
    })
  },
  switchLine2: function () {
    this.setData({
      line: 2
    })
  },
  // 点击读取data-id，从而获取button的id，将id传入全局变量
  switchDetail: function (e) {
    var $id = e.currentTarget.dataset.id.id;
    app.globalData.idx = $id;
    this.setData({
      idx: $id
    })
    wx.navigateTo({
      url: '../detail/detail'
    })
  },
  // 遍历获取各站点名称
  onShow: function () {
    let line1Data = [];
    let line2Data = [];
    for (let i = 0; i < app.globalData.data[0].station.length; i++) {
      line1Data.push({
        id: [0, i],
        name: app.globalData.data[0].station[i].name
      })
    }
    for (let i = 0; i < app.globalData.data[1].station.length; i++) {
      line2Data.push({
        id: [1, i],
        name: app.globalData.data[1].station[i].name
      })
    }
    this.setData({
      line1Data: line1Data,
      line2Data: line2Data
    })
  }
})
